home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue51 / SafeCall / HResultDecoderU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-16  |  2.4 KB  |  89 lines

  1. unit HResultDecoderU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     edtHRESULT: TEdit;
  12.     Label1: TLabel;
  13.     lblS: TLabel;
  14.     GroupBox1: TGroupBox;
  15.     lblR: TLabel;
  16.     lblC: TLabel;
  17.     lblN: TLabel;
  18.     lblMsgID: TLabel;
  19.     lblFacility: TLabel;
  20.     lblSCode: TLabel;
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure edtHRESULTChange(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. uses
  35.   TypInfo;
  36.  
  37. {$R *.DFM}
  38.  
  39. procedure TForm1.FormCreate(Sender: TObject);
  40. begin
  41.   if Assigned(edtHRESULT.OnChange) then
  42.     edtHRESULT.OnChange(edtHRESULT)
  43. end;
  44.  
  45. procedure TForm1.edtHRESULTChange(Sender: TObject);
  46. var
  47.   HRes: HResult;
  48.   Facility, SCode: Integer;
  49.   TmpStr: String;
  50. const
  51.   Sev: array[Boolean] of String = ('Failure', 'Success');
  52. begin
  53.   try
  54.     HRes := StrToInt(edtHRESULT.Text);
  55.     lblS.Caption := Format('Severity: %s',
  56.       [Sev[HResultFacility(HRes) = Severity_Success]]);
  57.     lblR.Caption := Format('NT''s second severity bit: %s',
  58.       [BooleanIdents[(HRes shr 30) and $1 <> 0]]);
  59.     lblC.Caption := Format('NT''s C field: %s',
  60.       [BooleanIdents[(HRes shr 29) and $1 <> 0]]);
  61.     lblN.Caption := Format('Mapped NT status field: %s',
  62.       [BooleanIdents[HRes and Facility_NT_Bit <> 0]]);
  63.     lblMsgID.Caption := Format('Msg id: %s',
  64.       [BooleanIdents[(HRes shr 27) and $1 <> 0]]);
  65.     Facility := HResultFacility(HRes);
  66.     TmpStr := IntToHex(Facility, 2);
  67.     case Facility of
  68.       FACILITY_NULL:      TmpStr := 'FACILITY_NULL';
  69.       FACILITY_RPC:       TmpStr := 'FACILITY_RPC';
  70.       FACILITY_DISPATCH:  TmpStr := 'FACILITY_DISPATCH';
  71.       FACILITY_STORAGE:   TmpStr := 'FACILITY_STORAGE';
  72.       FACILITY_ITF:       TmpStr := 'FACILITY_ITF';
  73.       FACILITY_SSPI:      TmpStr := 'FACILITY_SSPI';
  74.       FACILITY_WIN32:     TmpStr := 'FACILITY_WIN32';
  75.       FACILITY_WINDOWS:   TmpStr := 'FACILITY_WINDOWS';
  76.       FACILITY_CONTROL:   TmpStr := 'FACILITY_CONTROL';
  77.       FACILITY_CERT:      TmpStr := 'FACILITY_CERT';
  78.       FACILITY_INTERNET:  TmpStr := 'FACILITY_INTERNET';
  79.     end;
  80.     lblFacility.Caption := 'Facility code: ' + TmpStr;
  81.     SCode := HResultCode(HRes);
  82.     lblSCode.Caption := Format('SCODE: $%x', [SCode]);
  83.   except
  84.  
  85.   end
  86. end;
  87.  
  88. end.
  89.